package com.cutthroatcreations.woodenrailway;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class YearListFragment extends ListFragment {
	private static final String TAG = "YearList";
	private OnYearSelectedListener yearSelectedListener;
	private setTextViewYear stv;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

			setListAdapter(new ArrayAdapter<String>(getActivity(),
					android.R.layout.simple_list_item_1,
					WoodenApplication.cYears));
			stv.setTextView();
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {

		yearSelectedListener.onYearSelected(position);
	}

	public interface OnYearSelectedListener {
		public void onYearSelected(int id);
	}

	public interface setTextViewYear {
		public void setTextView();
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);

		try {
			stv = (setTextViewYear) activity;
			yearSelectedListener = (OnYearSelectedListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString()
					+ " must implement OnYearSelectedListener");
		}
	}
}
